package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.system.domain.SysCityData;
import com.ruoyi.system.mapper.SysCityDataMapper;
import com.ruoyi.system.service.ISysCityDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 城市管理Service业务层处理
 *
 * @author ruoyi
 * @date 2021-09-27
 */
@Service
public class SysCityDataServiceImpl implements ISysCityDataService {
    @Autowired
    private SysCityDataMapper sysCityDataMapper;

    /**
     * 查询城市管理
     *
     * @param id 城市管理主键
     * @return 城市管理
     */
    @Override
    public SysCityData selectSysCityDataById(Integer id) {
        return sysCityDataMapper.selectSysCityDataById(id);
    }

    /**
     * 查询城市管理列表
     *
     * @param sysCityData 城市管理
     * @return 城市管理
     */
    @Override
    public List<SysCityData> selectSysCityDataList(SysCityData sysCityData) {
        return sysCityDataMapper.selectSysCityDataList(sysCityData);
    }

    /**
     * 新增城市管理
     *
     * @param sysCityData 城市管理
     * @return 结果
     */
    @Override
    public int insertSysCityData(SysCityData sysCityData) {
        return sysCityDataMapper.insertSysCityData(sysCityData);
    }

    /**
     * 修改城市管理
     *
     * @param sysCityData 城市管理
     * @return 结果
     */
    @Override
    public int updateSysCityData(SysCityData sysCityData) {
        return sysCityDataMapper.updateSysCityData(sysCityData);
    }

    /**
     * 批量删除城市管理
     *
     * @param ids 需要删除的城市管理主键
     * @return 结果
     */
    @Override
    public int deleteSysCityDataByIds(String ids) {
        return sysCityDataMapper.deleteSysCityDataByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除城市管理信息
     *
     * @param id 城市管理主键
     * @return 结果
     */
    @Override
    public int deleteSysCityDataById(Integer id) {
        return sysCityDataMapper.deleteSysCityDataById(id);
    }

    /**
     * 查询城市管理树列表
     *
     * @return 所有城市管理信息
     */
    @Override
    public List<Ztree> selectSysCityDataTree(SysCityData cityData) {
        List<SysCityData> sysCityDataList = sysCityDataMapper.selectSysCityDataList(cityData);
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (SysCityData sysCityData : sysCityDataList) {
            Ztree ztree = new Ztree();
            ztree.setId(sysCityData.getId().longValue());
            if (sysCityData.getParentid() != null) {
                ztree.setpId(sysCityData.getParentid().longValue());
            } else {
                ztree.setpId(0L);
            }
//            ztree.setpId(0L);
            ztree.setName(sysCityData.getAreaname());
            ztree.setTitle(sysCityData.getAreaname());
            ztrees.add(ztree);
        }
        return ztrees;
    }

}
